#include <allegro.h>
#include <stdio.h>
#include "fct.h"

#define GFX_W 800
#define GFX_H 600
#define nb_images_bonus 3



int main() {

	char chemin_background[]="background.bmp";//bech ijib background

	BITMAP *Buffer;
	BITMAP *Background=NULL;//ifarag l'adresse
	
	Rebecca R;

	int compteur;

	/* General initialization function */
	allegro_init();
	if (install_keyboard() == -1) 
	{
		allegro_message("Error! %s", allegro_error);
		return (-1);
	}
	set_color_depth(32);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, GFX_W, GFX_H, 0, 0) != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
		allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
		return (1);
	}

	Buffer = create_bitmap(SCREEN_W, SCREEN_H);
	//loading images
	//loading Rebecca                       //appel 
	load_Rebecca(&R);
        //loading background
	Background=load_background_bmp(chemin_background);
	


	//init position & direction
	compteur = 0;
	init_Rebecca(&R);

	while (!key[KEY_ESC]) {
		
		//drawing background
		draw_background(Background,Buffer);
		//drawing Rebecca
		draw_Rebecca_bonus(&R,Buffer,compteur);
		//blit Buffer to screen
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		//vider le buffer
		clear_bitmap(Buffer);
		compteur++;
		sleep(1);		
		//usleep(200000);
		if (compteur == 3)
			compteur = 0;
	}
	//destroy Rebecca
	destroy_Rebecca(&R);
	destroy_background(Background);
	destroy_bitmap(Buffer);
	return (0);
}
END_OF_MAIN();




